{include file="public/header" /}

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>项目定制</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <form method="get" name="formSearch" id="formSearch">
        <div class="ds-search-form">
            <dl>
                <dt>商品名称：</dt>
                <dd><input type="text" value="{$Request.get.search_goods_name|default=''}" name="search_goods_name" id="search_goods_name" class="txt"></dd>
            </dl>
            <div class="btn_group">
                <input type="hidden" value="{$project_id}" name="project_id">
                <input type="hidden" value="{$order_id}" name="order_id" id="order_id">
                <a href="javascript:document.formSearch.submit();" class="btn " title="{$Think.lang.ds_query}">{$Think.lang.ds_query}</a>

                {if $search_goods_name != '' || $store_name != ''}
                <a href="{:url('Goodproject/projec_goods',['project_id'=>$project_id])}" class="btn btn-default"
                   title="{$Think.lang.ds_cancel}">{$Think.lang.ds_cancel}</a>
                {/if}
                <a href="javascript:void(0);" onclick="edit_band_goods({$order_id},{$project_id});" class="btn">导入商品</a>

                <a href="javascript:void(0);" class="btn" id="btn2">生成商品单</a>
                <!-- <a href="javascript:void(0);" class="btn2">生成商品单</a> -->
            </div>
        </div>
        <input type="hidden" value="" name="export">
    </form>
    <div class="explanation" id="explanation">
        <div class="title" id="checkZoom">
            <h4 >{$Think.lang.ds_explanation}</h4>
            <span></span>
        </div>
        <ul>
            <li style="font-size:14px;">当前项目定制标题为：{$title}</li>
        </ul>
    </div>
    <table class="ds-default-table">
        <thead>
        <tr>

            <th>商品</th>
            <th class="w272 align-center">商品名称及规格值</th>
            <th class=" align-center">单价</th>
            <th class="w172 align-center">数量</th>
            <th class="w200 align-center">{$Think.lang.ds_handle}</th>
        </tr>
        </thead>

        <tbody>
        {notempty name="goods_list"}
        {foreach name="goods_list" item="type"}
        {if $type.goods_name != ''}
        <tr>
            <td class="w60 picture">
                <div class="size-56x56"><span class="thumb size-56x56"><i></i><img src="{$type.goods_image}" onload="javascript:ResizeImage(this,56,56);"/></span>
                </div>
            </td>
            <td>{$type.goods_name}</td>
            <td>{$type.goods_price}</td>
            <td>{$type.goods_num}</td>
            <td>
                <a class="dsui-btn-edit" href="javascript:dsLayerOpen('{:url('projectorder/num',['rec_id'=>$type.rec_id])}','编辑-{$type.goods_name}','500px','300px')"><i class="iconfont"></i>编辑数量</a>

                <a href="javascript:dsLayerConfirm('{:url('projectorder/goods_drop',['rec_id'=>$type.rec_id])}','{$Think.lang.ds_ensure_del}')" class="dsui-btn-del"><i class="iconfont"></i>{$Think.lang.ds_del}</a>
            </td>
        </tr>
        {/if}
        {/foreach}
        {/notempty}
        </tbody>
    </table>
</div>
<script>
    $(document).on('click', '#btn2', function() {
        var order_id = $("#order_id").val();
        var obj = $(this);
        $.ajax({
            type: 'POST',
            url: "{:url('projectorder/create_goods')}",
            cache: false,
            data: {order_id:order_id},
            dataType: 'json',
            success: function (data) {
                if(data.code==0){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href=data.url;return false;
                    }, 2000);
                }else{
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href=data.url;return false;
                    }, 2000);
                }
            }
        });return false;
    });

    //按钮先执行验证再提交表单
    $(function(){

        var textButton1="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
        $(textButton1).insertBefore("#project_images");
        $("#project_images").change(function(){$("#textfield1").val($("#project_images").val());});
        jQuery.validator.addMethod("initial", function(value, element) {
            return /^[A-Za-z0-9]$/i.test(value);
        }, "");
        $("#brand_form").validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules : {
                brand_name : {
                    required : true,
                    remote   : {
                        url :"{:url('Brand/ajax','branch=check_brand_name')}",
                        type:'get',
                        data:{
                            brand_name : function(){
                                return $('#brand_name').val();
                            },
                            id  : '{$project_id}'
                        }
                    }
                },
                brand_initial : {
                    initial  : true
                },
                brand_sort : {
                    number   : true,
                    range : [0,255]
                }
            },
            messages : {
                brand_name : {
                    required : '{$Think.lang.brand_add_name_null}',
                    remote   : '{$Think.lang.brand_add_name_exists}'
                },
                brand_initial : {
                    initial : '{$Think.lang.brand_add_initial}'
                },
                brand_sort  : {
                    number   : '{$Think.lang.brand_add_sort_int}',
                    range : '{$Think.lang.class_sort_explain}'
                }
            }
        });
    });

    gcategoryInit('gcategory');

    function edit_band_goods(ids_str,ids_str2) {
        _uri = ADMINSITEURL+"/projectorder/edit_band_goods?order_id=" + ids_str+"&project_id="+ids_str2;
        dsLayerOpen(_uri,'导入商品','1100px','800px');
    }
    $(function () {
        $('a[dstype="batch"]').click(function () {
            if ($('.checkitem:checked').length == 0) {    //没有选择
                layer.alert('<?php echo \think\Lang::get('select_record_want_operate'); ?>');
                return false;
            }
            var _items = '';
            $('.checkitem:checked').each(function () {
                _items += $(this).val() + ',';
            });
            _items = _items.substr(0, (_items.length - 1));

            var data_str = '';
            eval('data_str = ' + $(this).attr('data-param'));

            if (data_str.sign == 'jingle') {
                ajax_form('ajax_jingle', '<?php echo \think\Lang::get('advertising'); ?>', data_str.urls + '?commonid=' + _items + '&inajax=1', '480');
            } else if (data_str.sign == 'plate') {
                ajax_form('ajax_plate', '<?php echo \think\Lang::get('set_associated_layout'); ?>', data_str.urls + '?commonid=' + _items + '&inajax=1', '480');
            }
        });
    });
    //查看详情
    function goods_setting_info(ids_str) {
        _uri = HOMESITEURL+"/Goodproject/detail?project_id=" + ids_str;
        dsLayerOpen(_uri,'查看详情','800px','600px');
    }
    /**
     * Layer 通用ifram弹出窗口
     */
    function dsLayerOpen(url, title,width,height) {
        if (!width) width = '900px';
        if (!height) height = '500px';
        layer.open({
            type: 2,
            title: title,
            area: [width,height],
            fixed: false, //不固定
            maxmin: true,
            content: url
        });
    }
</script>